// JavaScript Document

var FormTest = function(){
//提交第一步
	this.error1 = false;	
	this.error2 = false;	
	this.error3 = false;	
	this.error4 = false;	
	this.error5 = false;	
	this.error6 = false;	
	this.error7 = false;	

	$('zusername').onblur = function(){
		request = send_request();
		request.onreadystatechange = Fromcheck.processrequest;
		var username = this.value;
		var tipsob = $('usertips');
		tipsob.className='tips';
		Fromcheck.error1 = false;
		
		if(username==""){
			tipsob.innerHTML="请先输入用户名";
			return false;
		}else if(username.length < 6){
			tipsob.innerHTML="输入的用户名不能少于6字节";
			return false;
		}else{
			reobj = tipsob;
			tipsob.innerHTML="正在发送数据...";
			url = '/module/ajax/checkuser/index.php?username='+username;
			//确定发送请求方式，URL，及是否同步执行下段代码
			request.open("GET",url,true);
			request.send(null);
		}
	}
	$('zpassword').onblur=function(){
		var nodevalue = this.value;
		var tipsob = $('passwordtips');
		tipsob.className='tips';
		Fromcheck.error2 = false;
		if(nodevalue.length < 6){
			tipsob.innerHTML="密码长度在6-20之间";
		}else if(nodevalue.length > 20){
			tipsob.innerHTML="密码长度在6-20之间";
		}else{
			tipsob.innerHTML="正确";
			Fromcheck.error2 = true;
		}
		if($('repeat_one').value){
			if($('repeat_one').value != nodevalue){
				$('repeat_onetips').innerHTML="两次密码输入不一致";
				Fromcheck.error3 = false;
			}else{
				$('repeat_onetips').innerHTML="正确";
				Fromcheck.error3 = true;
			}
		}
	}
	$('repeat_one').onblur=function(){
		var password = $('zpassword').value;
		var nodevalue = this.value;
		var tipsob = $('repeat_onetips');
		tipsob.className='tips';
		Fromcheck.error3 = false;
		if(nodevalue != password){
			tipsob.innerHTML="两次密码输入不一致";
		}else{
			tipsob.innerHTML="正确";
			Fromcheck.error3 = true;
		}
	}
	$('zemail').onblur = function(){
		var re = new RegExp(RegExp_Email); 
		var nodevalue = this.value;
		var tipsob = $('zemailtips');
		tipsob.className='tips';
		Fromcheck.error4 = false;	
		if( nodevalue.length < 1 ){
			tipsob.innerHTML = "邮箱地址不能为空";
		}else{
			if(nodevalue.match(re) == null){
				tipsob.innerHTML = "邮箱格式不正确";
			}else{
				tipsob.innerHTML="正确";
				Fromcheck.error4 = true;	
			}
		}
	}
	$('imgcode').onblur = function(){
		var nodevalue = this.value;
		var tipsob = $('imgcodetips');
		tipsob.className='tips';
		Fromcheck.error5 = false;
		if(nodevalue.length < 4){
			tipsob.innerHTML = "验证码有误";
		}else{
			tipsob.className='';
			tipsob.innerHTML = "";
			Fromcheck.error5 = true;
		}
	}
}
	//处理返回信息的函数
FormTest.prototype.processrequest = function(){
	var data='';
	if(request.readyState==4){//判断对象状态
		if(request.status==200){//信息已成功返回，开始处理信息
			var results = request.responseText;
			/*
			var results = request.responseXML;
			//var results = request.responseText;
			var xmldata = results.getElementsByTagName("data");
 			for (var i = 0; i< xmldata.length; i++){
				data =  xmldata[i];
				name = data.getElementsByTagName("mesg")[0].firstChild.nodeValue;
			}
			*/
			if(results == 1){
				reobj.innerHTML = '用户名已经存在';
			}else if(results == 2){
				reobj.innerHTML = '恭喜您可以注册这个用户';
				Fromcheck.error1 = true;
			}else if(results == 3){
				reobj.innerHTML = '用户名不能为空';
			}else{
				reobj.innerHTML = '用户名书写不正确';
			}
		}else{//页面不正常
			//alert("您所请求的页面不正常！");
		}
	}
}

FormTest.prototype.AllSubmit = function(){
	if(!this.error1){
		$('zusername').focus();
		return false;
	}
	if(!this.error2){
		$('zpassword').focus();
		return false;
	}
	if(!this.error3){
		$('repeat_one').focus();
		return false;
	}
	if(!this.error4){
		$('zemail').focus();
		return false;
	}
	if(!this.error5){
		$('imgcode').focus();
		return false;
	}
	var flag = this.error1 && this.error2 && this.error3 && this.error4 && this.error5;
	if(flag){
		$('submit').disabled = true;
	}
	return flag;
}

window.onload=function(){
	Fromcheck = new FormTest();
}













